﻿@using PagedList;
@using PagedList.Mvc;
@model IPagedList<Project_2._2.Models.Role>
@{
    ViewBag.Title = "Quản Lý Phân Quyền";
    Layout = "~/Views/Shared/_AdminLayoutPage.cshtml";
    Project_2._2.Models.QuanLyThueXeEntities db = new Project_2._2.Models.QuanLyThueXeEntities();
}

<script src="~/Script/Jquery_Table_Sort/jquery-latest.js"></script>
<script src="~/Script/Jquery_Table_Sort/jquery.tablesorter.js"></script>

<script type="text/javascript">
    $(document).ready(function () {
        $("table").tablesorter({ sortList: [[0, 0]], headers: { 0: { sorter: false }, 9: { sorter: false } } });
    });

</script>

<style>
    .search {
        width: 100%;
        height: 40px;
        padding: 10px 0 5px 10px;
    }

    .test {
        background: url('../Images/AdminDesign/nav-item-current-bg.png') repeat-x;
    }
</style>

<div class="grid_12">
    <div class="block-border">
        <div class="block-header">
            QUẢN LÝ PHÂN QUYỀN
            @Html.ActionLink("Thêm Mới", "Create", "AdminRole", null, new { @class = "button" })
            @if(ViewBag.SBy != "0" && ViewBag.SBy != null )
            { 
                @Html.ActionLink("Trở Lại Danh Sách", "Default", "AdminRole", null, new { @class="button"})
            }
        </div>
        <div class="block-content">

            <div class="search">

                @using (Html.BeginForm("Default", "AdminRole", FormMethod.Post, new { id = "Form" }))
                {
                    List<SelectListItem> record = new List<SelectListItem>();
                    int macdinh = 10;
                    if (ViewBag.record != null)
                    {
                        macdinh = int.Parse(ViewBag.record);
                    }
                    else
                    {
                        macdinh = 10;
                    }
                    for (int i = 10; i <= 50; i += 5)
                    {
                        if (macdinh == i)
                        { record.Add(new SelectListItem { Text = i + " Dòng", Value = i.ToString(), Selected = true }); }
                        else
                        { record.Add(new SelectListItem { Text = i + " Dòng", Value = i.ToString() }); }
                    }

                    <div style="float:left; margin-top:5px">Hiển Thị &nbsp;@Html.DropDownList("soDong", record, new { @class = "select", onchange = "SelectedIndexChanged()" })</div>

                    /////// -------------   ////
                    List<SelectListItem> SearchBy = new List<SelectListItem>();
                    SearchBy.Add(new SelectListItem { Text = "Tìm Theo Tên", Value = "Name" });
                    if (ViewBag.SBy != null)
                    {
                        foreach (var item in SearchBy)
                        {
                            if (item.Value == ViewBag.SBy)
                            { item.Selected = true; break; }
                        }
                    }
                    else
                    { SearchBy[0].Selected = true; }
                    //// ------------------ ///
                    List<SelectListItem> kieuTK = new List<SelectListItem>();
                    kieuTK.Add(new SelectListItem { Text = "Tìm gần đúng", Value = "1" });
                    kieuTK.Add(new SelectListItem { Text = "Tìm chính xác", Value = "2" });
                    if (ViewBag.SType != null)
                    {
                        foreach (var item in kieuTK)
                        {
                            if (item.Value == ViewBag.SType)
                            {
                                item.Selected = true;
                                break;
                            }
                        }
                    }
                    else
                    {
                        kieuTK[0].Selected = true;
                    }
                    ////
                    <table style="float:right; padding-right:20px">
                        <tr>

                            <td>Từ Khóa&nbsp;&nbsp;&nbsp;</td>
                            <td>@Html.TextBox("KeyWorld", null, new { @class = "Textbox", @placeholder = "Nhập từ khóa ...", @Value = ViewBag.Key })</td>
                            <td>@Html.DropDownList("SearchBy", SearchBy, new { @class = "select", style = "display:none;" })</td>
                            <td>@Html.DropDownList("SearchType", kieuTK, new { @class = "select" })</td>
                            <td><input type="submit" value="Tìm Kiếm" class="MyButton" /></td>
                        </tr>
                    </table>
                }

            </div>
            @if (Model.Count != 0)
            {
                using (Html.BeginForm("Multi_Delete", "AdminRole", FormMethod.Post))
                {
                    <table class="tablesorter" cellpadding="0" cellspacing="0">
                        <thead>
                            <tr>
                                <th style="text-align: center; color: #cfdee5">Chọn</th>
                                <th style="text-align: center" title="Sắp xếp">Mã Role</th>
                                <th style="text-align: center" title="Sắp xếp">Tên Role</th>
                                <th style="text-align: center" title="Sắp xếp">Mô Tả</th>
                                <th style="text-align: center"></th>
                            </tr>
                        </thead>
                        <tbody>

                            @for (int i = 0; i < Model.Count; i++)
                            {
                                if (i % 2 != 0)
                                {
                                    <tr style="background-color:#f3f3f3">
                                        <td style="text-align:center"><input type="checkbox" name="RoleIdsToDelete" id="RoleIdsToDelete" value="@Model[i].RoleId"></td>
                                        <td style="text-align: left ; padding-left:10px">@Model[i].RoleId</td>
                                        <td style="text-align: left ; padding-left:10px">@Model[i].TenRole</td>
                                        <td style=" text-align: left; padding-left: 10px">@Model[i].MoTa</td>
                                        <td style="width:70px">
                                            <a class="tableActionButton edit" rel="tooltip-top" title="Xem Chi Tiết " href="@Url.Action("Update", "AdminRole", new { id = Model[i].RoleId })"></a>

                                            <a class="tableActionButton delete" rel="tooltip-top" title="Xóa Tài Khoản" href="@Url.Action("Delete", "AdminRole", new { id = Model[i].RoleId })" onclick="return DeleteConfirm()"></a>
                                        </td>
                                    </tr>
                                }
                                else
                                {
                                   <tr style="background-color:#f3f3f3">
                                        <td style="text-align:center"><input type="checkbox" name="RoleIdsToDelete" id="RoleIdsToDelete" value="@Model[i].RoleId"></td>
                                       <td style="text-align: left ; padding-left:10px">@Model[i].RoleId</td>
                                       <td style="text-align: left ; padding-left:10px">@Model[i].TenRole</td>
                                        <td style=" text-align: left; padding-left: 10px">@Model[i].MoTa</td>
                                        <td style="width:70px">
                                            <a class="tableActionButton edit" rel="tooltip-top" title="Xem Chi Tiết " href="@Url.Action("Update", "AdminRole", new { id = Model[i].RoleId })"></a>

                                            <a class="tableActionButton delete" rel="tooltip-top" title="Xóa Tài Khoản" href="@Url.Action("Delete", "AdminRole", new { id = Model[i].RoleId })" onclick="return DeleteConfirm()"></a>
                                        </td>
                                    </tr>
                                }
                            }

                        </tbody>

                    </table>
                    <div style="margin:13px 0 0 10px; float:left"><input type="submit" class="MyButton" value="Xóa Dòng đã Chọn" onclick="return DeleteConfirm()" /> </div>
                }
                <table cellpadding="0" cellspacing="0" style="border-top:none; margin:5px 0px 5px 0; float:right;   ">
                    <tr>

                        <td style="width:65px; text-align:right; font-weight:bold;padding-top:2px ">
                            <span style="border: 1px solid #808080; border-right: none; padding: 7px 15px; margin-top: 10px; border-radius: 4px 0 0 4px; background-color: #428bca; color:#ffffff"> Trang</span>
                        </td>
                        <td>
                            @if (ViewBag.Key == null && ViewBag.SBy == null)
                            {
                                @Html.PagedListPager(Model, page => Url.Action("Default", new { page, rd = ViewBag.record }), new PagedListRenderOptions() { LinkToFirstPageFormat = "<<", LinkToPreviousPageFormat = " < ", LinkToNextPageFormat = " > ", LinkToLastPageFormat = ">>" })
                            }
                            else
                            {
                                @Html.PagedListPager(Model, page => Url.Action("Default", new { page, rd = ViewBag.record, key = ViewBag.Key, SBy = ViewBag.SBy, SType = ViewBag.SType }), new PagedListRenderOptions() { LinkToFirstPageFormat = "<<", LinkToPreviousPageFormat = " < ", LinkToNextPageFormat = " > ", LinkToLastPageFormat = ">>" })
                            }
                        </td>
                        <td style="width:10px"></td>
                    </tr>
                </table>
            }
            else
            {
                <hr style="width:100%" />
                <div style="color:red ; font-size:large ; padding-left:10px ; padding-bottom:10px"><span>Không có dữ liêu .</span></div>
            }
            <div style="clear:right"></div>
        </div>
    </div>
</div>
<script>

    function DeleteConfirm() {
        if (confirm("Tất cả dữ liệu liên quan điều sẽ bị xóa.\nBạn có muốn xóa không ?"))
            return true;
        else
            return false;
    }

    function SelectedIndexChanged() {
        $('#Form').submit();
    }
    document.getElementById("acc").setAttribute("class", "activee")
</script>


